package com.demo.listener;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "Demo06Servlet", urlPatterns = "/demo06.do")
public class Demo06Servlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //创建和获取Session对象 都是用这个方法
        HttpSession session = request.getSession();
        //isNew() 判断是否刚创建 true/false
        System.out.println(session.isNew());
        System.out.println(session.getId());
        //session作为域对象使用 略过
        //获取Session的超时时间
        System.out.println(session.getMaxInactiveInterval());

        //设置session超时时间,以秒为单位
//        session.setMaxInactiveInterval(1 * 60);

        //session直接超时无效
        session.invalidate();
    }
}
